package com.sys.utils;

import java.io.*;

public class TextWriter {

    public static void write(String fileName,String charset,boolean append,String content) throws IOException {

        FileOutputStream fos = null;
        OutputStreamWriter osw = null;
        BufferedWriter bw = null;
        try {
            fos = new FileOutputStream(fileName,append);
            osw = new OutputStreamWriter(fos,charset);
            bw = new BufferedWriter(osw);
            bw.write(content);
        } catch (FileNotFoundException e) {
            throw e;
        } catch (UnsupportedEncodingException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        }finally {
            if(bw!=null){
                try {
                    bw.close();
                } catch (IOException e) {
                    throw e;
                }
            }
            if(osw!=null){
                try {
                    osw.close();
                } catch (IOException e) {
                    throw e;
                }
            }
            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    throw e;
                }
            }
        }

    }
}
